﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing ;

using Qiang.Topology.Geometries;

namespace Qiang.Data
{
    /// <summary>
    /// 节点类
    /// </summary>
    [Serializable]
    public class NodeShape : Shape,INodeShape
    {

        # region 初始化

       
        /// <summary>
        /// 
        /// </summary>
        /// <param name="point"></param>
        public NodeShape(Coordinate point)
            : base()
        {           
            this._point = point;
            this._segmentCollection = new List<ISegmentShape>();
            ID = "节点" + Count.ToString();
            Count++;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public NodeShape(double x, double y)
        {
            _point = new Coordinate(x, y);
            _segmentCollection = new List<ISegmentShape>();
        }

        # endregion


        static int Count = 0;


        # region 属性
             

        private Coordinate _point;

        /// <summary>
        /// 坐标
        /// </summary>
        public Coordinate Point
        {
            get { return _point; }
            set { _point = value; }
        }

        private List<ISegmentShape> _segmentCollection;

        /// <summary>
        /// 与节点相连的弧段
        /// </summary>
        public List<ISegmentShape> SegmentCollection
        {
            get { return _segmentCollection; }
            set { _segmentCollection = value; }
        }

        /// <summary>
        /// shape类型.
        /// </summary>
        public override ShapeType ShapeType
        {
            get
            {
                return ShapeType.Node;
            }
        }
                 

        # endregion


        #region 继承的方法

        /// <summary>
        /// 获取图形的范围
        /// </summary>
        /// <returns></returns>
        protected override IExtent ComputeExtent()
        {
            if (this._point == null) return Qiang.Data.Extent.Empty();
            return new Extent(this._point.X, this._point.Y, this._point.X, this._point.Y);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override IList<Coordinate> ComputeCoordinates()
        {
            return new List<Coordinate>() { _point };
        }


        #endregion



        public override IGeometry ToGeometry()
        {
            IPoint point = new Qiang.Topology.Geometries.Point(new DefaultCoordinateSequence(Coordinates.ToArray()), new GeometryFactory());
            return point;
        }

       
    }
}
